<!DOCTYPE html>
<html>

<head lang="en">
  <meta charset="UTF-8">
  <title>量词</title>
</head>

<body>
  <script>
    //量词 注意*在这里是量词，不是充当通配符，充当通配符的是 .
    //? 出现0次或1次（最多出现1次）
    console.log("AaBbAb_AaaBbbAba".replace(/Aa?/g,0));

    //+ 出现1次或多次（至少出现1次）
    console.log("AaBbAb_AaaBbbAba".replace(/Aa+/g,0));

    //* 出现0次或多次（任意次）
    console.log("AaBbAb_AaaBbbAba".replace(/Aa*/g,0));

    //{n} 出现n次
    console.log("AaBbAb_AaaBbbAba".replace(/Aa{1}/g,0));
    console.log("AaBbAb_AaaBbbAba".replace(/Aa{2}/g,0));

    //{n,m} 出现n到m次
    console.log("AaBbAb_AaaBbbAba".replace(/Aa{1,2}/g,0));

    //{n,} 出现至少n次
    console.log("AaBbAb_AaaBbbAbaAaaaaaaAaaAaaa".replace(/Aa{2,}/g,0));
    //console.log("AaBbAb_AaaBbbAbaAaaaaaaAaaAaaa".replace(/Aa{2,4}/g,0));

    //注意：0到n次的写法{0,n}而不是{,n}

    //思考：
    var reg = /d{20}\w\d?\w+\d*\w{3,5}\d{3,}/;

  
    //n+	  匹配任何包含至少一个 n 的字符串。
    var pattern = /8+/g;
    //var str = "123456789012";
    //var str = "12345679012";
    var str = "1234567889012";
    console.log(str);
    console.log(pattern.test(str));
    console.log(str.replace(pattern, "$"));

    //n*	  匹配任何包含零个或多个 n 的字符串。
    var pattern = /8*/g;
    //var str = "1234567890";
    //var str = "123456790";
    var str = "12345678890";
    console.log(str);
    console.log(pattern.test(str));
    console.log(str.replace(pattern, "$"));


    //n?	  匹配任何包含零个或一个 n 的字符串。
    var pattern = /8?/g;
    //var str = "1234567890";
    //var str = "123456790";
    //var str = "12345678890";
    console.log(str);
    console.log(pattern.test(str));
    console.log(str.replace(pattern, "$"));

    // n{x}	  匹配包含 x 个 n 的序列的字符串。
    var pattern = /\d{9}/g;
    //var str = "abc12345678";
    //var str = "abc123456789";
    //var str = "abc1234567890";
    console.log(str);
    console.log(pattern.test(str));
    console.log(str.replace(pattern, "$"));


    // n{x,}	  匹配包含至少 x 个 n 的序列的字符串。
    var pattern = /\d{9,}/g;
    //var str = "abc12345678";
    //var str = "abc123456789";
    //var str = "abc1234567890";
    console.log(str);
    console.log(pattern.test(str));
    console.log(str.replace(pattern, "$"));


    // n{x,y}	  匹配包含 x 至 y 个 n 的序列的字符串。
    var pattern = /\d{5,10}/g;
    //var str = "abc1234";
    //var str = "abc12345";
    //var str = "abc1234567";
    //var str = "abc1234567890";
    //var str = "abc1234567890123";
    console.log(str);
    console.log(pattern.test(str));
    console.log(str.replace(pattern, "$"));
  </script>
</body>

</html>